<template>
	<view class='flex commonHead'
		:style="{color: (navInfo.color ? navInfo.color:'#000'),backgroundColor:(navInfo.bg_color ? navInfo.bg_color: 'unset'),height:commonHeadHeight.titleHeight+'px'}">
		<view class='commonHead-wrap flex'>
			<!-- 0:无返回；1：返回上一级；2：home -->
			<view class='commonHead_left'>
				<uni-icons v-if="!isShowHome" type="back" size="30" @click="commonHead_left_back"></uni-icons>
				<!-- <uni-icons v-if="isShowHome" type="home" size="30" @click="commonHead_left_home"></uni-icons> -->
				<!-- <view class='commonHead_left_back' @click="commonHead_left_back"></view> -->
				<!-- <view v-if="navInfo.flag==1" class='commonHead_left_back' @click='commonHead_left_back'></view> -->
				<!-- <view v-else-if="navInfo.flag==2" class='commonHead_left_home' @click='commonHead_left_home'></view> -->
			</view>
			<view class='commonHead_right flex' v-if="navInfo.name">
				<view class='commonHead_right_text line1'>{{navInfo.name}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			navInfo: {
				type: Object,
				value: {
					"bg_color": "white",
					"color": "#fff",
					"flag": 1,
					"name": "我是标题"
				}
			}
		},
		data() {
			return {
				commonHeadHeight: {},
				titleHeight: '',
				statusBarHeight: '',
				isShowHome: false
			}
		},

		mounted() {
			var that = this;
			const routes = getCurrentPages()
			if (routes.length <= 1) {
				this.isShowHome = true
			} else {
				this.isShowHome = false
			}
			uni.getSystemInfo({
				success(res) {
					that.commonHeadHeight.statusBarHeight = (34 * 2)
					that.commonHeadHeight.titleHeight = res.statusBarHeight + 46
					that.statusBarHeight = (34 * 2)
					that.titleHeight = res.statusBarHeight + 46
				}
			})
		},
		methods: {
			commonHead_left_back() {
				uni.navigateBack();
			},
			commonHead_left_home() {
				uni.reLaunch({
					url: '/pages/home/home'
				})
			}
		}

	}
</script>
<style lang="scss" scoped>
	@import './custom-component.scss';
</style>